return translation;
}
+gchar *
+_gtk_builder_parser_translate (const gchar *domain,
+ const gchar *context,
+ const gchar *text)
+{
+ const char *s;
+
+ if (context)
+ s = dpgettext (domain, context, text);
+ else
+ s = dgettext (domain, text);
+
+ return g_strdup (s);
+}
+
/* Called for close tags </foo> */
static void
end_element (GMarkupParseContext *context,
if (prop_info->translatable && prop_info->text->len)
{
- const char *text;
-
- if (prop_info->context)
- text = dpgettext (data->domain,
- prop_info->context,
- prop_info->text->str);
- else
- text = dgettext (data->domain, prop_info->text->str);
-
- prop_info->data = g_strdup (text);
+ prop_info->data = _gtk_builder_parser_translate (data->domain,
+ prop_info->context,
+ prop_info->text->str);
g_string_free (prop_info->text, TRUE);
}
else
{
- prop_info->data = prop_info->text->str;
- g_string_free (prop_info->text, FALSE);
+ prop_info->data = g_string_free (prop_info->text, FALSE);
+
}
object_info->properties =
#include "gtktreednd.h"
#include "gtkintl.h"
#include "gtkbuildable.h"
+#include "gtkbuilderprivate.h"
#include "gtkalias.h"
#define GTK_LIST_STORE_IS_SORTED(list) (((GtkListStore*)(list))->sort_column_id != GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID)
* <column type="..."/>
* </columns>
*/
+typedef struct {
+ gboolean translatable;
+ gchar *context;
+ int id;
+} ColInfo;
+
typedef struct {
GtkBuilder *builder;
GObject *object;
GSList *column_type_names;
GType *column_types;
GValue *values;
- gint *columns;
+ gint *colids;
+ ColInfo **columns;
gint last_row;
gint n_columns;
gint row_column;
GQuark error_quark;
gboolean is_data;
+ const gchar *domain;
} SubParserData;
static void
if (strcmp (element_name, "col") == 0)
{
int i, id = -1;
+ gchar *context = NULL;
+ gboolean translatable = FALSE;
+ ColInfo *info;
if (data->row_column >= data->n_columns)
g_set_error (error, data->error_quark, 0,
id = atoi (values[i]);
if (errno)
g_set_error (error, data->error_quark, 0,
- "the id tag %s could not be converted to an integer", values[i]);
+ "the id tag %s could not be converted to an integer",
+ values[i]);
+ }
+ else if (strcmp (names[i], "translatable") == 0)
+ {
+ if (!_gtk_builder_boolean_from_string (values[i], &translatable,
+ error))
+ return;
+ }
+ else if (strcmp (names[i], "comments") == 0)
+ {
+ /* do nothing, comments are for translators */
+ }
+ else if (strcmp (names[i], "context") == 0)
+ {
+ context = g_strdup (values[i]);
}
if (id == -1)
g_set_error (error, data->error_quark, 0,
"<col> needs an id attribute");
+
+ info = g_slice_new0 (ColInfo);
+ info->translatable = translatable;
+ info->context = context;
+ info->id = id;
- data->columns[data->row_column] = id;
+ data->colids[data->row_column] = id;
+ data->columns[data->row_column] = info;
data->row_column++;
data->is_data = TRUE;
}
gtk_list_store_insert_with_valuesv (GTK_LIST_STORE (data->object),
&iter,
data->last_row,
- data->columns,
+ data->colids,
data->values,
data->row_column);
for (i = 0; i < data->row_column; i++)
- g_value_unset (&data->values[i]);
+ {
+ ColInfo *info = data->columns[i];
+ g_free (info->context);
+ g_slice_free (ColInfo, info);
+ data->columns[i] = NULL;
+ g_value_unset (&data->values[i]);
+ }
g_free (data->values);
data->values = g_new0 (GValue, data->n_columns);
data->last_row++;
gint i;
GError *tmp_error = NULL;
gchar *string;
+ ColInfo *info;
if (!data->is_data)
return;
i = data->row_column - 1;
+ info = data->columns[i];
string = g_strndup (text, text_len);
+ if (info->translatable && text_len)
+ {
+ gchar *translated;
+
+ /* FIXME: This will not use the domain set in the .ui file,
+ * since the parser is not telling the builder about the domain.
+ * However, it will work for gtk_builder_set_translation_domain() calls.
+ */
+ translated = _gtk_builder_parser_translate (data->domain,
+ info->context,
+ string);
+ g_free (string);
+ string = translated;
+ }
+
if (!gtk_builder_value_from_string_type (data->builder,
data->column_types[i],
string,
parser_data->builder = builder;
parser_data->object = G_OBJECT (buildable);
parser_data->values = g_new0 (GValue, n_columns);
- parser_data->columns = g_new0 (gint, n_columns);
+ parser_data->colids = g_new0 (gint, n_columns);
+ parser_data->columns = g_new0 (ColInfo*, n_columns);
parser_data->column_types = GTK_LIST_STORE (buildable)->column_headers;
parser_data->n_columns = n_columns;
parser_data->last_row = 0;
parser_data->error_quark = g_quark_from_static_string ("GtkListStore");
+ parser_data->domain = gtk_builder_get_translation_domain (builder);
*parser = list_store_parser;
*data = parser_data;
}
else if (strcmp (tagname, "data") == 0)
{
+ int i;
+ for (i = 0; i < sub->n_columns; i++)
+ {
+ ColInfo *info = sub->columns[i];
+ if (info)
+ {
+ g_free (info->context);
+ g_slice_free (ColInfo, info);
+ }
+ }
+ g_free (sub->colids);
g_free (sub->columns);
g_free (sub->values);
g_slice_free (SubParserData, sub);